package controllers

import (
	"errors"
	"github.com/gin-gonic/gin"
)

const UserIdKey = "UserId"

var ErrorUserNotLogin = errors.New("用户未登录")

func GetCurrentUser(c *gin.Context) (userId int64, err error) {
	value, exists := c.Get(UserIdKey)
	if !exists {
		err = ErrorUserNotLogin
		return
	}
	uid, ok := value.(int64)
	if !ok {
		err = ErrorUserNotLogin
		return
	}
	return uid, nil
}
